package cn.zhz.controller;

import cn.zhz.pojo.Electronic;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@Controller
public class ElectController {
    @RequestMapping("/add")
    public String add(){
        return "add";
    }
    @RequestMapping("/save")
    public String elect(String number, String type, String price, String theDate, Model model) throws ParseException {
        Electronic electronic=new Electronic();
        electronic.setNumber(Integer.valueOf(number));
        electronic.setModel(type);
        electronic.setPrice(new BigDecimal(price));
        electronic.setTheDate(new SimpleDateFormat("yyyy-MM-dd").parse(theDate));
        model.addAttribute(electronic);
        return "save";
    }
}
